<?php

class CompanyModel extends BaseModel
{
    var $table  = 'company';
    var $prikey = 'company_id';
    var $_name  = 'company';
	
    var $_relation = array(
		'has_member' => array(
            'model'         => 'member',
            'type'          => HAS_MANY,
            'foreign_key'   => 'company_id'
        ),
		'has_brand' => array(
            'model'         => 'brand',
            'type'          => HAS_MANY,
            'foreign_key'   => 'company_id'
        )
	);

        /*
     * 判断名称是否唯一
     */
    function unique($company_name, $company_id = 0)
    {
        $conditions = "company_name = '" . $company_name . "' AND company_id != ".$company_id."";
        return count($this->find(array('conditions' => $conditions))) == 0;
    }
}

?>